VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsConnect"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Public Function ConnectionString() As String
On Error GoTo PROC_EXIT

    Dim ReturnValue As String
    Dim SoftwareMindkeyKeyTaxConnString As String
    
    Dim AdoDBServer As Object
    Dim AdoDBServerConnectionString As String
    
    SoftwareMindkeyKeyTaxConnString = GetSettingC("Software\Mindkey\KeyTax", "ConnectionString")
    
    'If the value is not set up in Software\Mindkey\KeyTax, check the ADOConnectionstring value
    If Len(SoftwareMindkeyKeyTaxConnString) > 0 Then
        ReturnValue = SoftwareMindkeyKeyTaxConnString
    Else
        Set AdoDBServer = CreateObject("ADODBServer.clsDBFunctions")
        
        AdoDBServer.InitConnect , "Keytax SQL", "KeyTax"
        
        AdoDBServerConnectionString = AdoDBServer.ConnectionString()
        
        ReturnValue = AdoDBServerConnectionString
    End If
    
PROC_EXIT:
    Set AdoDBServer = Nothing
    
    ConnectionString = ReturnValue
End Function ' ConnectionString

Public Function ConnectionStringIS() As String
  ConnectionStringIS = GetSettingC("Software\Mindkey\KeyTax", "ConnectionStringIS")
End Function ' ConnectionString

Public Function ConnectionStringBlueprntDev() As String
  ConnectionStringBlueprntDev = GetSettingC("Software\Mindkey\KeyTax", "ConnectionStringBlueprntDev")
End Function ' ConnectionString


Private Function Encrypt(ByVal strText As String, _
                        ByVal strCipher As String) As String
  Dim lngIndex As Long
  Dim strEncryptedText As String
  Dim lngCipherLength As Long
  Dim strTextArray() As String
  Dim lngHolder As Long
  Dim strTextHolder As String
  Dim strTextToLongHolder As String
  Dim i As Long


  'check to see if the text sent in is a bunch of numbers
  lngHolder = Val(strText)
  If lngHolder = 0 Then 'this is a string that does not need conversion from the character codes back to a string
    strTextHolder = strText
  Else 'this is a long that needs to be converted back to a string
    ReDim strTextArray(0)

    strTextArray = Split(strText, "~", -1)
    For i = 0 To UBound(strTextArray) - 1
        strTextHolder = strTextHolder & Chr(strTextArray(i))
    Next
  End If
  'both the return and the Text to encrypt need to be longs so
    'that they are not truncated when
  'they get saved or displayed

  'convert the Text to a long

  lngCipherLength = Len(strCipher)

  Do Until Len(strEncryptedText) = Len(strTextHolder)
    For lngIndex = 1 To lngCipherLength

      ' We are done when the two strings are equal in length
      If Len(strEncryptedText) = Len(strTextHolder) Then
        Exit For
      End If

      ' Perform the XOR encryption
      strEncryptedText = strEncryptedText & _
        Chr(Asc(Mid(strTextHolder, Len(strEncryptedText) + 1, 1)) Xor _
        Asc(Mid(strCipher, lngIndex, 1)))
    Next lngIndex
  Loop

  'check the the return value if its a decrypted string COOL

  If lngHolder <> 0 Then ' this is a decrypted string
    ' Return the encrypted/decrypted text
    Encrypt = strEncryptedText
  Else 'this is an encrypted string and needs to be converted to longs
    For i = 1 To Len(strEncryptedText)
        strTextToLongHolder = strTextToLongHolder & Asc(Mid$(strEncryptedText, i, 1)) & "~"
    Next
    'return the long'ed encrypted string
    Encrypt = strTextToLongHolder
  End If

End Function

